﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.DataContract;
using WordNet.Core.ElementContracts;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestDataLineAdjective:UnitTestBase
    {
        const string DATA_LINE_ADJECTIVE = @"00001740 00 a 01 able 0 005 = 05138679 n 0000 = 05546715 n 0000 + 05546715 n 0101 + 05138679 n 0101 ! 00002098 a 0101 | (usually followed by `to') having the necessary means or skill or know-how or authority to do something; ""able to swim""; ""she was able to program her computer""; ""we were at last able to buy a car""; ""able to get a grant for the project"" ";
        const string DATA_LINE_ADJECTIVE_SATELITE = @"00020484 00 s 01 rejected 0 001 & 00020037 a 0000 | something or someone judged unacceptable; ""rejected merchandise""";
        const string DATA_LINE_ADJECTIVE_IP = @"01608019 00 s 01 galore(ip) 0 001 & 01607490 a 0000 | in great numbers; ""daffodils galore"" ";
        
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }

        [TestMethod]
        public void CanParseAdjectiveData()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);
        }

        [TestMethod]
        public void CanParseAdjectiveSatelite()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE_SATELITE);
            Assert.IsNotNull(synset);
            Assert.IsTrue(synset.IsAdjectiveSatellite);
        }

        [TestMethod]
        public void CanParseSyntacticMarker()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE_IP);
            Assert.IsNotNull(synset);
            Assert.IsTrue(synset.GetWords()[0].AdjectiveMarker.Symbol == AdjectiveMarker.POSTNOMINAL.Symbol);
            Assert.IsTrue(synset.GetWords()[0].AdjectiveMarker.Description == AdjectiveMarker.POSTNOMINAL.Description);
        }

        [TestMethod]
        public void CanParseAdjectiveDataOffset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(int.Parse("00001740"), synset.Offset);

        }

        [TestMethod]
        public void CanParseAdjectiveDataLexFile()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(0, synset.LexicalFile.Number);
            Assert.AreEqual(POS.ADJECTIVE, synset.LexicalFile.PartOfSpeech);
            Assert.AreEqual(LexFile.ADJ_ALL.Name, synset.LexicalFile.Name);

            Assert.AreEqual(LexFile.GetLexicalFile(0), synset.LexicalFile);
        }

        [TestMethod]
        public void CanParseAdjectiveDataPOS()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);
            Assert.AreEqual(POS.ADJECTIVE, synset.PartOfSpeech);
        }

        [TestMethod]
        public void CanParseAdjectiveDataNumberOfWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);

            Assert.AreEqual(Convert.ToInt32("01", 16), synset.GetWords().Count);
        }

        [TestMethod]
        public void CanParseAdjectiveDataWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);

            string expectedValue = "able";
            Assert.AreEqual(expectedValue, synset.GetWord(1).Lemma);
            Assert.AreEqual(0, synset.GetWord(1).LexicalID);
        }

        [TestMethod]
        public void CanParseAdjectiveDataSynsetPointers()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);

            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.ATTRIBUTE));
            Assert.IsTrue(synset.GetWords()[0].GetRelatedMap().ContainsKey(Pointer.DERIVATIONALLY_RELATED));
            Assert.IsTrue(synset.GetWords()[0].GetRelatedMap().ContainsKey(Pointer.ANTONYM));
        }

        [TestMethod]
        public void CanParseAdjectiveDataGloss()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_ADJECTIVE);
            Assert.IsNotNull(synset);
            Assert.IsTrue(DATA_LINE_ADJECTIVE.Trim().EndsWith(synset.Gloss));
        }

    }
}
